home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / misc / port / oldstuff / portsource.lha / Port122.S < prev    next >
Encoding:
Text File  |  1993-02-19  |  15.2 KB  |  1,152 lines

  1. testmode    =    1
  2.  
  3.     include    "src:shadowlord.i"
  4.  
  5. ; V1.01
  6. ; Added bigger understanding of PC box characters.
  7. ; Now also understands one-wide box chars, and thick corner changed to #,
  8. ; single corner to +.
  9.  
  10. ; V1.02
  11. ; Added bad mode error, and error on no space between mode and the rest.
  12.  
  13. ; V1.10
  14. ; Cut endspace.
  15. ; Text output.
  16.  
  17. ; V1.13
  18. ; Percentage & size change
  19. ; extra lf
  20. ; extra cr removal in topc mode
  21.  
  22. ; V1.16
  23. ; Faster translate routines  25% speedup in frompc
  24. ; 6 more in frompc
  25. ; New helptext.
  26.  
  27. ; V1.18  11-feb
  28. ; Upper and lower case modes.
  29.  
  30. ; V1.22  19-feb
  31. ; tabs to spaces
  32. ; 3 new pc box chars
  33. ; bug fixed that confused port if the end of the commandline had spaces.
  34. ; spaces to tabs
  35.  
  36. * 19-Feb-93
  37. * 16 days of hard coding
  38.  
  39. ; during the program
  40. ; a0=source
  41. ; a1=dest
  42. ; a2=spacebuf
  43.  
  44. ; d0=current char
  45. ; d1=load counter
  46. ; d2=savebyte counter
  47.  
  48.  
  49.     if    testmode=1
  50.     lea    test_comline,a0
  51.     move.l    #test_len,d0
  52.     endc
  53.  
  54. progstart:
  55.     clr.b    -1(a0,d0.l)
  56.     move.l    a0,commandstart
  57.     move.w    d0,commandlen
  58.     add.l    d0,a0
  59.     subq.l    #1,a0
  60.     move.l    a0,commandend
  61.  
  62.     lea    dosname,a1
  63.     moveq    #0,d0
  64.     move.l    execbase,a6
  65.     jsr    openlibrary(a6)
  66.     move.l    d0,dosbase
  67.  
  68.     move.l    dosbase,a6
  69.     jsr    output(a6)
  70.     move.l    d0,outstruct
  71.  
  72.     if    testmode=1
  73.     bne    err_testmode
  74.     endc
  75.  
  76.     move.l    #text_cursoroff,d2
  77.     moveq    #5,d3
  78.     bsr    printtext
  79.  
  80.     move.l    commandstart,a0
  81.     tst.b    (a0)            ; if blank commandline, instructions
  82.     beq    helptext
  83.     cmp.b    #"?",(a0)
  84.     beq    helptext
  85.  
  86. parsestart:
  87.     cmp.b    #"-",(a0)
  88.     beq    checkoption
  89.  
  90. parse:
  91.     cmp.b    #" ",1(a0)        ; at least one space after option
  92.     bne    err_nocomlinespace
  93.     cmp.b    #"p",(a0)
  94.     beq    frompcmode
  95.     cmp.b    #"P",(a0)
  96.     beq    topcmode
  97.     cmp.b    #"s",(a0)
  98.     beq    fromsf7mode
  99.     cmp.b    #"S",(a0)
  100.     beq    tosf7mode
  101.     cmp.b    #"u",(a0)
  102.     beq    toupcasemode
  103.     cmp.b    #"l",(a0)
  104.     beq    tolowcasemode
  105.     bra    err_badmode
  106.  
  107. checkoption:
  108.     cmp.b    #"n",1(a0)
  109.     beq    opt_nocutspace
  110.     cmp.b    #"?",1(a0)
  111.     beq    credits
  112.     cmp.b    #"t",1(a0)
  113.     beq    opt_tabconv
  114.     cmp.b    #"s",1(a0)
  115.     beq    opt_spaceconv
  116.     bra    err_badcomline
  117.  
  118. opt_nocutspace:
  119.     clr.b    mode_cutspace
  120.     addq.l    #2,a0
  121.     cmp.b    #" ",(a0)
  122.     bne    err_badcomline
  123.     bsr    skipspace
  124.     cmp.l    #0,a0
  125.     beq    err_badcomline
  126.     bra    parsestart
  127.  
  128. opt_tabconv:
  129.     addq.l    #2,a0            ; can be optimized; drop second
  130.     move.b    (a0),d0            ; addq.l #n,a0
  131.     ext.w    d0
  132.     ext.l    d0
  133.     cmp.b    #" ",d0
  134.     beq    opt_tabconv2
  135.     sub.b    #"0",d0
  136.     cmp.b    #9,d0
  137.     bhi    err_badcomline
  138.     cmp.b    #1,d0
  139.     bcs    err_badcomline
  140.     move.b    d0,tabsize
  141.     addq.l    #1,a0
  142.     cmp.b    #" ",(a0)
  143.     bne    err_badcomline
  144.  
  145. opt_tabconv1:
  146.     bsr    skipspace
  147.     cmp.l    #0,a0
  148.     beq    err_badcomline
  149.     bra    parsestart
  150.  
  151. opt_tabconv2:
  152.     move.b    #8,tabsize
  153.     bra    opt_tabconv1
  154.  
  155. opt_spaceconv:
  156.     addq.l    #2,a0
  157.     move.b    (a0),d0
  158.     ext.w    d0
  159.     ext.l    d0
  160.     cmp.b    #" ",d0
  161.     beq    opt_spaceconv2
  162.     sub.b    #"0",d0
  163.     cmp.b    #9,d0
  164.     bhi    err_badcomline
  165.     cmp.b    #1,d0
  166.     bcs    err_badcomline
  167.     move.b    d0,spacesize
  168.     move.b    d0,tabsize
  169.     addq.l    #1,a0
  170.     cmp.b    #" ",(a0)
  171.     bne    err_badcomline
  172.  
  173. opt_spaceconv1:
  174.     bsr    skipspace
  175.     cmp.l    #0,a0
  176.     beq    err_badcomline
  177.     bra    parsestart
  178.  
  179. opt_spaceconv2:
  180.     move.b    #8,spacesize
  181.     bra    opt_spaceconv1
  182.  
  183. frompcmode:
  184.     move.b    #1,mode
  185.     bra    nameparse
  186.  
  187. fromsf7mode:
  188.     move.b    #2,mode
  189.     bra    nameparse
  190.  
  191. tosf7mode:
  192.     move.b    #-2,mode
  193.     bra    nameparse
  194.  
  195. topcmode:
  196.     move.b    #-1,mode
  197.     bra    nameparse
  198.  
  199. toupcasemode:
  200.     move.b    #3,mode
  201.     bra    nameparse
  202.     
  203. tolowcasemode:
  204.     move.b    #4,mode
  205.     bra    nameparse
  206.  
  207. nameparse:
  208.     addq.l    #1,a0
  209.     bsr    skipspace
  210.     cmp.l    #0,a0
  211.     beq    err_badcomline
  212.     move.l    a0,sourcenamestart
  213.     bsr    findend
  214.     cmp.l    #0,a0
  215.     beq    err_badcomline
  216.     move.l    a0,sourcenameend
  217.     addq.l    #1,a0
  218.     sub.l    sourcenamestart,a0
  219.     move.l    a0,sourcenamelen
  220.  
  221.     move.l    sourcenamestart,a0
  222.     move.l    #sourcename,a1
  223.     move.l    sourcenamelen,d0
  224.     subq.l    #1,d0
  225.     cmp.b    #'"',(a0)
  226.     beq    removequotes
  227.  
  228. copysourcename:
  229.     move.b    (a0)+,(a1)+
  230.     dbf    d0,copysourcename
  231.     clr.b    (a1)
  232.  
  233.     move.l    sourcenameend,a0
  234.     addq.l    #1,a0
  235.     cmp.l    commandend,a0
  236.     beq    nodest
  237.  
  238.     bsr    skipspace
  239.     cmp.l    #0,a0
  240.     beq    nodest
  241.     move.l    a0,destnamestart
  242.     bsr    findend
  243.     cmp.l    #0,a0
  244.     beq    err_badcomline
  245.     move.l    a0,destnameend
  246.     addq.l    #1,a0
  247.     sub.l    destnamestart,a0
  248.     move.l    a0,destnamelen
  249.     move.l    a0,d0
  250.  
  251.     move.l    destnamestart,a0
  252.     move.l    #destname,a1
  253.     subq.l    #1,d0
  254.     cmp.b    #'"',(a0)
  255.     beq    removequotes1
  256.  
  257. copydestname:
  258.     move.b    (a0)+,(a1)+
  259.     dbf    d0,copydestname
  260.     bra    openfiles
  261.  
  262. removequotes:
  263.     addq.l    #1,a0
  264.     subq.l    #2,d0
  265.     bra    copysourcename
  266.  
  267. removequotes1:
  268.     addq.l    #1,a0
  269.     subq.l    #2,d0
  270.     bra    copydestname
  271.  
  272. removequotes2:
  273.     addq.l    #1,a0
  274.     subq.l    #2,d0
  275.     bra    copydestname1
  276.  
  277. nodest:
  278.     move.l    #destname,a1
  279.     move.l    sourcenamestart,a0
  280.     move.l    sourcenamelen,d0
  281.     subq.l    #1,d0
  282.     cmp.b    #'"',(a0)
  283.     beq    removequotes2
  284.  
  285. copydestname1:
  286.     move.b    (a0)+,(a1)+
  287.     dbf    d0,copydestname1
  288.  
  289.     cmp.b    #-1,mode
  290.     beq    pcsuffix
  291.     cmp.b    #-2,mode
  292.     beq    sf7suffix
  293.  
  294. amigasuffix:
  295.     lea    text_amigasuf,a0
  296.     moveq    #4-1,d0
  297.  
  298. amigasuffix1:
  299.     move.b    (a0)+,(a1)+
  300.     dbf    d0,amigasuffix1
  301.     bra    openfiles
  302.  
  303. pcsuffix:
  304.     lea    text_pcsuf,a0
  305.     moveq    #3-1,d0
  306.  
  307. pcsuffix1:
  308.     move.b    (a0)+,(a1)+
  309.     dbf    d0,pcsuffix1
  310.     bra    openfiles
  311.  
  312. sf7suffix:
  313.     lea    text_sf7suf,a0
  314.     moveq    #4-1,d0
  315.  
  316. sf7suffix1:
  317.     move.b    (a0)+,(a1)+
  318.     dbf    d0,sf7suffix1
  319.  
  320. openfiles:
  321.     clr.b    (a1)            ; end of filename
  322.     move.l    #sourcename,d1
  323.     move.l    #1005,d2
  324.     move.l    dosbase,a6
  325.     jsr    open(a6)
  326.     tst.l    d0
  327.     beq    err_nosource
  328.     move.l    d0,sourcehandle
  329.  
  330.     move.l    #destname,d1
  331.     move.l    #1006,d2
  332.     move.l    dosbase,a6
  333.     jsr    open(a6)
  334.     tst.l    d0
  335.     beq    err_nodest
  336.     move.l    d0,desthandle
  337.  
  338. readblock:
  339.     move.l    sourcehandle,d1
  340.     move.l    #sourcebuf,d2
  341.     move.l    #1024,d3
  342.     move.l    dosbase,a6
  343.     jsr    read(a6)
  344.     add.l    d0,readbytes
  345.     move.l    d0,d1
  346.     beq    closefiles        ; readbytes=0 - quit
  347.     subq.l    #1,d1
  348.     moveq    #0,d2
  349.  
  350.     lea    sourcebuf,a0
  351.     lea    destbuf,a1
  352.  
  353. morecharacters:
  354.     move.b    (a0)+,d0
  355.     bra    cutspace
  356.  
  357. checknormal:
  358.     cmp.b    #-2,mode
  359.     beq    tosf7
  360.     cmp.b    #-1,mode
  361.     beq    topc
  362.     cmp.b    #2,mode
  363.     beq    fromsf7
  364.     cmp.b    #3,mode
  365.     beq    toupcase
  366.     cmp.b    #4,mode
  367.     beq    tolowcase
  368.  
  369. frompc:
  370.     cmp.b    #" ",d0
  371.     bcs    frompc1
  372.     cmp.b    #"~",d0
  373.     bhi    frompc1
  374.     bra    nextchar
  375.  
  376. frompc1:
  377.     cmp.b    #$84,d0
  378.     beq    ami_lowae
  379.     cmp.b    #$94,d0
  380.     beq    ami_lowoe
  381.     cmp.b    #$8e,d0
  382.     beq    ami_upae
  383.     cmp.b    #$99,d0
  384.     beq    ami_upoe
  385.     cmp.b    #13,d0
  386.     beq    nochar
  387.     cmp.b    #0,d0
  388.     beq    nochar
  389.     cmp.b    #$1a,d0            ; ctrl+z
  390.     beq    nochar
  391.     cmp.b    #$c9,d0
  392.     beq    ami_bigcorner
  393.     cmp.b    #$bb,d0
  394.     beq    ami_bigcorner
  395.     cmp.b    #$c8,d0
  396.     beq    ami_bigcorner
  397.     cmp.b    #$bc,d0
  398.     beq    ami_bigcorner
  399.     cmp.b    #$cd,d0
  400.     beq    ami_doubleline
  401.     cmp.b    #$ba,d0
  402.     beq    ami_upline
  403.     cmp.b    #$b3,d0
  404.     beq    ami_upline
  405.     cmp.b    #$b0,d0
  406.     beq    ami_box
  407.     cmp.b    #$b1,d0
  408.     beq    ami_box
  409.     cmp.b    #$b2,d0
  410.     beq    ami_box
  411.     cmp.b    #$c4,d0
  412.     beq    ami_singleline
  413.     cmp.b    #$c0,d0
  414.     beq    ami_smallcorner
  415.     cmp.b    #$d9,d0
  416.     beq    ami_smallcorner
  417.     cmp.b    #$bf,d0
  418.     beq    ami_smallcorner
  419.     cmp.b    #$da,d0
  420.     beq    ami_smallcorner
  421.     cmp.b    #$d4,d0
  422.     beq    ami_bigcorner
  423.     cmp.b    #$c3,d0
  424.     beq    ami_smallcorner
  425.     cmp.b    #$b7,d0
  426.     beq    ami_smallcorner
  427.     cmp.b    #$b6,d0
  428.     beq    ami_bigcorner
  429.     cmp.b    #$d3,d0
  430.     beq    ami_smallcorner
  431.     cmp.b    #$d6,d0
  432.     beq    ami_smallcorner
  433.     cmp.b    #$bd,d0
  434.     beq    ami_smallcorner
  435.     cmp.b    #20,d0
  436.     beq    ami_182
  437.     cmp.b    #128,d0
  438.     beq    ami_231
  439.  
  440. nextchar:
  441.     move.b    d0,(a1)+
  442.     addq.l    #1,d2
  443.     addq.w    #1,col
  444.  
  445. nochar:
  446.     dbf    d1,morecharacters
  447.  
  448.     move.l    desthandle,d1
  449.     move.l    d2,d3
  450.     add.l    d2,writtenbytes
  451.     move.l    #destbuf,d2
  452.     move.l    dosbase,a6
  453.     jsr    write(a6)
  454.  
  455.     move.l    #text_input,d2
  456.     moveq    #15,d3
  457.     bsr    printtext
  458.  
  459.     lea    numberbuf,a0
  460.     move.l    readbytes,d0
  461.     bsr    num2ascii
  462.  
  463.     move.l    a0,d2
  464.     move.l    d0,d3
  465.     bsr    printtext
  466.  
  467.     move.l    #text_output,d2
  468.     moveq    #18,d3
  469.     bsr    printtext
  470.  
  471.     lea    numberbuf,a0
  472.     move.l    writtenbytes,d0
  473.     bsr    num2ascii
  474.  
  475.     move.l    a0,d2
  476.     move.l    d0,d3
  477.     bsr    printtext
  478.  
  479.     move.l    #text_cr,d2
  480.     moveq    #1,d3
  481.     bsr    printtext
  482.  
  483.     bra    readblock
  484.  
  485. cutspace:
  486.     move.l    spacepointer,a2
  487.     cmp.b    #" ",d0
  488.     beq    addspace
  489.     cmp.b    #9,d0            ; tab
  490.     beq    addtab
  491.  
  492.     cmp.b    #1,mode_cutspace
  493.     bne    cutspace2
  494.  
  495.     cmp.b    #10,d0            ; lf
  496.     beq    cutspaces
  497.     cmp.b    #13,d0            ; cr
  498.     beq    cutspaces
  499.  
  500. cutspace1:
  501.     tst.l    tabs
  502.     bne    linkspaces
  503.  
  504. cutspace3:
  505.     tst.l    spacenumber
  506.     bne    linkspaces2
  507.     bra    checknormal
  508.  
  509. cutspace2:
  510.     cmp.b    #10,d0
  511.     beq    clearcol
  512.     cmp.b    #13,d0
  513.     beq    clearcol
  514.     bra    cutspace1
  515.  
  516. clearcol:
  517.     move.w    #-1,col
  518.     bra    cutspace1
  519.  
  520. addspace:
  521.     addq.l    #1,spacenumber
  522.     move.b    d0,(a2)+
  523.     move.l    a2,spacepointer
  524.     addq.w    #1,col
  525.     bra    checkconvspace
  526.  
  527. addtab:
  528.     move.b    tabsize,d4        ; if tabsize is zero, just add it
  529.     bne    tabconv
  530.     bra    addspace
  531.  
  532. tabconv:
  533.     ext.w    d4
  534.     ext.l    d4
  535.     move.w    col,d3
  536.     ext.l    d3
  537.     divu    d4,d3
  538.     swap    d3
  539.     sub.w    d3,d4
  540.     add.l    d4,spacenumber
  541.     add.w    d4,col
  542.     subq.w    #1,d4
  543.     move.b    #" ",d0
  544.  
  545. tabconv1:
  546.     move.b    d0,(a2)+
  547.     dbf    d4,tabconv1
  548.     move.l    a2,spacepointer
  549.  
  550. checkconvspace:
  551.     tst.b    spacesize
  552.     beq    nochar
  553.     cmp.l    #1,spacenumber        ; if spacenumber<=1, skip
  554.     bls    nochar
  555.     move.w    col,d5
  556.     ext.l    d5
  557.     move.l    spacenumber,d3
  558.     move.b    spacesize,d4
  559.     ext.w    d4
  560.     ext.l    d4
  561.  
  562.     divu    d4,d5
  563.     swap    d5
  564.     tst.w    d5
  565.     beq    foundconvspace
  566.     bra    nochar
  567.  
  568. foundconvspace:
  569.     move.l    #spacebuf,spacepointer
  570.     addq.l    #1,tabs
  571.     clr.l    spacenumber
  572.     bra    nochar
  573.  
  574. cutspaces:
  575.     clr.l    spacenumber
  576.     clr.l    tabs
  577.     move.l    #spacebuf,spacepointer
  578.     move.w    #-1,col            ; col will be zero when eol gets added
  579.     bra    checknormal
  580.  
  581. linkspaces:
  582.     move.l    tabs,d3
  583.     clr.l    tabs
  584.     add.l    d3,d2            ; tabs -> bytes to be written
  585.     subq.l    #1,d3
  586.  
  587. linkspaces1:
  588.     move.b    #9,(a1)+
  589.     dbf    d3,linkspaces1
  590.     bra    cutspace3
  591.  
  592. linkspaces2:
  593.     move.l    spacenumber,d3
  594.     add.l    d3,d2            ; spaces -> bytes to be written
  595.     subq.l    #1,d3
  596.     lea    spacebuf,a2
  597.     move.l    a2,spacepointer
  598.  
  599. linkspaces3:
  600.     move.b    (a2)+,(a1)+
  601.     dbf    d3,linkspaces3
  602.     clr.l    spacenumber
  603.     bra    checknormal
  604.  
  605. topc:
  606.     cmp.b    #"ä",d0
  607.     beq    pc_lowae
  608.     cmp.b    #"ö",d0
  609.     beq    pc_lowoe
  610.     cmp.b    #"Ä",d0
  611.     beq    pc_upae
  612.     cmp.b    #"Ö",d0
  613.     beq    pc_upoe
  614.     cmp.b    #13,d0
  615.     beq    nochar
  616.     cmp.b    #10,d0
  617.     beq    addcr
  618.     cmp.b    #0,d0
  619.     beq    nochar
  620.     cmp.b    #$1a,d0            ; ctrl+z
  621.     beq    nochar
  622.     bra    nextchar
  623.  
  624. fromsf7:
  625.     cmp.b    #"{",d0
  626.     beq    ami_lowae
  627.     cmp.b    #"|",d0
  628.     beq    ami_lowoe
  629.     cmp.b    #"[",d0
  630.     beq    ami_upae
  631.     cmp.b    #"\",d0
  632.     beq    ami_upoe
  633.     cmp.b    #13,d0
  634.     beq    nochar
  635.     cmp.b    #0,d0
  636.     beq    nochar
  637.     cmp.b    #$1a,d0            ; ctrl+z
  638.     beq    nochar
  639.     bra    nextchar
  640.  
  641. tosf7:
  642.     cmp.b    #"ä",d0
  643.     beq    sf7_lowae
  644.     cmp.b    #"ö",d0
  645.     beq    sf7_lowoe
  646.     cmp.b    #"Ä",d0
  647.     beq    sf7_upae
  648.     cmp.b    #"Ö",d0
  649.     beq    sf7_upoe
  650.     cmp.b    #10,d0
  651.     beq    addcr
  652.     cmp.b    #0,d0
  653.     beq    nochar
  654.     cmp.b    #$1a,d0            ; ctrl+z
  655.     beq    nochar
  656.     bra    nextchar
  657.  
  658. toupcase:
  659.     cmp.b    #"ä",d0
  660.     beq    ami_upae
  661.     cmp.b    #"ö",d0
  662.     beq    ami_upoe
  663.     cmp.b    #"a",d0
  664.     bcs    nextchar
  665.     cmp.b    #"z",d0
  666.     bhi    nextchar
  667.  
  668.     eor.b    #%100000,d0
  669.     bra    nextchar
  670.  
  671. tolowcase:
  672.     cmp.b    #"Ä",d0
  673.     beq    ami_lowae
  674.     cmp.b    #"Ö",d0
  675.     beq    ami_lowoe
  676.     cmp.b    #"A",d0
  677.     bcs    nextchar
  678.     cmp.b    #"Z",d0
  679.     bhi    nextchar
  680.  
  681.     or.b    #%100000,d0
  682.     bra    nextchar
  683.  
  684. ami_182:
  685.     move.b    #182,d0
  686.     bra    nextchar
  687.  
  688. ami_231:
  689.     move.b    #231,d0
  690.     bra    nextchar
  691.  
  692. ami_singleline:
  693.     move.b    #"-",d0
  694.     bra    nextchar
  695.  
  696. ami_box:
  697.     move.b    #$7f,d0
  698.     bra    nextchar
  699.  
  700. ami_upline:
  701.     move.b    #"|",d0
  702.     bra    nextchar
  703.  
  704. ami_doubleline:
  705.     move.b    #"=",d0
  706.     bra    nextchar
  707.  
  708. ami_smallcorner:
  709.     move.b    #"+",d0
  710.     bra    nextchar
  711.  
  712. ami_bigcorner:
  713.     move.b    #"#",d0
  714.     bra    nextchar
  715.  
  716. ami_lowae:
  717.     move.b    #"ä",d0
  718.     bra    nextchar
  719.  
  720. ami_lowoe:
  721.     move.b    #"ö",d0
  722.     bra    nextchar
  723.  
  724. ami_upae:
  725.     move.b    #"Ä",d0
  726.     bra    nextchar
  727.  
  728. ami_upoe:
  729.     move.b    #"Ö",d0
  730.     bra    nextchar
  731.  
  732. pc_lowae:
  733.     move.b    #$84,d0
  734.     bra    nextchar
  735.  
  736. pc_lowoe:
  737.     move.b    #$94,d0
  738.     bra    nextchar
  739.  
  740. pc_upae:
  741.     move.b    #$8e,d0
  742.     bra    nextchar
  743.  
  744. pc_upoe:
  745.     move.b    #$99,d0
  746.     bra    nextchar
  747.  
  748. sf7_lowae:
  749.     move.b    #"{",d0
  750.     bra    nextchar
  751.  
  752. sf7_lowoe:
  753.     move.b    #"|",d0
  754.     bra    nextchar
  755.  
  756. sf7_upae:
  757.     move.b    #"[",d0
  758.     bra    nextchar
  759.  
  760. sf7_upoe:
  761.     move.b    #"\",d0
  762.     bra    nextchar
  763.  
  764. addcr:
  765.     move.b    #13,(a1)+
  766.     addq.l    #1,d2
  767.     bra    nextchar
  768.  
  769. closefiles:
  770.     move.l    sourcehandle,d1
  771.     move.l    dosbase,a6
  772.     jsr    close(a6)
  773.     move.l    desthandle,d1
  774.     move.l    dosbase,a6
  775.     jsr    close(a6)
  776.  
  777.     move.l    #text_final,d2
  778.     moveq    #26,d3
  779.     bsr    printtext
  780.  
  781.     move.l    readbytes,d1
  782.     move.l    writtenbytes,d0
  783.  
  784.     sub.l    d1,d0
  785.     bmi    closefiles1        ; negative
  786.  
  787.     move.l    d0,d7
  788.     beq    closefiles2        ; if zero, no sign
  789.  
  790.     move.l    #text_possign,d2
  791.     moveq    #1,d3
  792.     bsr    printtext
  793.     bra    closefiles2
  794.  
  795. closefiles1:
  796.     neg.l    d0
  797.     move.l    d0,d7
  798.  
  799.     move.l    #text_negsign,d2
  800.     moveq    #1,d3
  801.     bsr    printtext
  802.  
  803. closefiles2:
  804.     move.l    d7,d0
  805.     lea    numberbuf,a0
  806.     bsr    num2ascii
  807.  
  808.     move.l    a0,d2
  809.     move.l    d0,d3
  810.     bsr    printtext
  811.  
  812.     move.l    #text_doublespace,d2
  813.     moveq    #2,d3
  814.     bsr    printtext
  815.  
  816.     move.l    writtenbytes,d0
  817.     move.l    readbytes,d1
  818.     bsr    percentage
  819.  
  820.     lea    numberbuf,a0
  821.     bsr    num2ascii
  822.  
  823.     move.l    a0,d2
  824.     move.l    d0,d3
  825.     bsr    printtext
  826.  
  827.     move.l    #text_percentsign,d2
  828.     move.l    #11,d3
  829.     bsr    printtext
  830.  
  831.     move.l    #text_lf,d2
  832.     move.l    #1,d3
  833.     bsr    printtext
  834.     bra    endprogram1
  835.  
  836. helptext:
  837.     move.l    #text_helptext,d2
  838.     move.l    #len_helptext,d3
  839.     bsr    printtext
  840.     bra    endprogram1
  841.  
  842. credits:
  843.     move.l    #text_credits,d2
  844.     move.l    #len_credits,d3
  845.     bsr    printtext
  846.     bra    endprogram1
  847.  
  848.     if    testmode=1
  849. err_testmode:
  850.     move.l    #$ffff,d0
  851.  
  852. err_testmode1:
  853.     move.w    #$f00,$dff180
  854.     dbf    d0,err_testmode1
  855.     bra    endprogram1
  856.     endc
  857.  
  858. err_nosource:
  859.     move.l    #text_nosource,d2
  860.     moveq    #36,d3
  861.     bsr    printtext
  862.     bra    endprogram1
  863.  
  864. err_nomemory:
  865.     move.l    #text_nomemory,d2
  866.     moveq    #26,d3
  867.     bsr    printtext
  868.     bra    endprogram1
  869.  
  870. err_badcomline:
  871.     move.l    #text_badcomline,d2
  872.     moveq    #25,d3
  873.     bsr    printtext
  874.     bra    endprogram1
  875.  
  876. err_nodest:
  877.     move.l    #text_nodest,d2
  878.     moveq    #41,d3
  879.     bsr    printtext
  880.     bra    endprogram2
  881.  
  882. err_badmode:
  883.     move.l    #text_badmode,d2
  884.     moveq    #32,d3
  885.     bsr    printtext
  886.     bra    endprogram1
  887.  
  888. err_nocomlinespace:
  889.     move.l    #text_nocomlinespace,d2
  890.     moveq    #60,d3
  891.     bsr    printtext
  892.     bra    endprogram1
  893.  
  894. endprogram1:
  895.     move.l    #text_cursoron,d2
  896.     moveq    #5,d3
  897.     bsr    printtext
  898.  
  899.     move.l    execbase,a6
  900.     move.l    dosbase,a1
  901.     jsr    closelibrary(a6)
  902.     moveq    #0,d0
  903.     rts
  904.  
  905. endprogram2:
  906.     move.l    sourcehandle,d1
  907.     move.l    dosbase,a6
  908.     jsr    close(a6)
  909.     bra    endprogram1
  910.  
  911. **********
  912. ** SUBS **
  913. **********
  914.  
  915. printtext:
  916.     if    testmode=1
  917.     rts
  918.     endc
  919.     move.l    outstruct,d1
  920.     move.l    dosbase,a6
  921.     jsr    write(a6)
  922.     rts
  923.  
  924. skipspace:
  925.     cmp.b    #" ",(a0)
  926.     beq    skipspace1
  927.     rts
  928.  
  929. skipspace1:
  930.     addq.l    #1,a0
  931.     cmp.l    commandend,a0
  932.     bcs    skipspace
  933.     move.l    #0,a0
  934.     rts
  935.  
  936. findend:
  937.     cmp.b    #'"',(a0)
  938.     beq    findend_quote
  939.  
  940. findend_space:
  941.     addq.l    #1,a0
  942.     cmp.b    #" ",(a0)
  943.     beq    findend_space1
  944.     cmp.b    #0,(a0)
  945.     beq    findend_space1
  946.     cmp.l    commandend,a0
  947.     bls    findend_space
  948.     move.l    #0,a0
  949.     rts
  950.  
  951. findend_space1:
  952.     subq.l    #1,a0
  953.     rts
  954.  
  955. findend_quote:
  956.     addq.l    #1,a0
  957.     cmp.b    #'"',(a0)
  958.     bne    findend_quote1
  959.     rts
  960.  
  961. findend_quote1:
  962.     cmp.l    commandend,a0
  963.     bls    findend_quote
  964.     move.l    #0,a0
  965.     rts
  966.  
  967.     include    "src:Num2ASCII-2.S"
  968.     include    "src:Percentage.S"
  969.  
  970. **********
  971. ** DATA **
  972. **********
  973.  
  974.     section    fastdata,data
  975.  
  976. spacepointer:
  977.     dc.l    spacebuf
  978.  
  979. text_helptext:
  980.     incbin    "src:Port/PortOpts1"
  981.  
  982. text_credits:
  983.     incbin    "src:Port/PortOpts2"
  984.  
  985. text_cursoroff:
  986.     dc.b    27,"[0 p"
  987.  
  988. text_cursoron:
  989.     dc.b    27,"[1 p"
  990.  
  991. text_badcomline:
  992.     dc.b    "ERROR!  Bad commandline.",10
  993.  
  994. text_nomemory:
  995.     dc.b    "ERROR!  Not enough memory.",10
  996.  
  997. text_badsource:
  998.     dc.b    "ERROR!  Bad sourcefile.",10
  999.  
  1000. text_nosource:
  1001.     dc.b    "ERROR!  Could not open source file.",10
  1002.  
  1003. text_nodest:
  1004.     dc.b    "ERROR!  Could not open destination file.",10
  1005.  
  1006. text_badmode:
  1007.     dc.b    "ERROR!  Bad mode specification.",10
  1008.  
  1009. text_nocomlinespace:
  1010.     dc.b    "ERROR!  The mode must be separated with at least one space.",10
  1011.  
  1012. text_input:
  1013.     dc.b    27,"[1mInput: ",27,"[0m"
  1014.  
  1015. text_output:
  1016.     dc.b    "  ",27,"[1mOutput: ",27,"[0m"
  1017.  
  1018. dosname:
  1019.     dc.b    "dos.library",0
  1020.  
  1021. text_amigasuf:
  1022.     dc.b    ".AMI"
  1023.  
  1024. text_pcsuf:
  1025.     dc.b    ".PC"
  1026.  
  1027. text_sf7suf:
  1028.     dc.b    ".SF7"
  1029.  
  1030. text_cr:
  1031.     dc.b    13
  1032.  
  1033. text_lf:
  1034.     dc.b    10
  1035.  
  1036. text_final:
  1037.     dc.b    27,"[1mFile size change:",27,"[0m "
  1038.  
  1039. text_negsign:
  1040.     dc.b    "-"
  1041.  
  1042. text_possign:
  1043.     dc.b    "+"
  1044.  
  1045. text_percentsign:
  1046.     dc.b    "%        "
  1047.  
  1048. text_doublespace:
  1049.     dc.b    "  "
  1050.  
  1051. mode_cutspace:
  1052.     dc.b    1
  1053.  
  1054.     if    testmode=1
  1055.  
  1056. test_comline:
  1057.     dc.b    "p ram:test1",10
  1058.  
  1059. test_comlineend:
  1060.  
  1061. test_len    =    test_comlineend-test_comline
  1062.     endc
  1063.  
  1064.     section    fastblank,bss
  1065.  
  1066. tabs:
  1067.     ds.l    1
  1068.  
  1069. writtenbytes:
  1070.     ds.l    1
  1071.  
  1072. readbytes:
  1073.     ds.l    1
  1074.  
  1075. sourcehandle:
  1076.     ds.l    1
  1077.  
  1078. desthandle:
  1079.     ds.l    1
  1080.  
  1081. outstruct:
  1082.     ds.l    1
  1083.  
  1084. destnamestart:
  1085.     ds.l    1
  1086.  
  1087. destnameend:
  1088.     ds.l    1
  1089.  
  1090. destnamelen:
  1091.     ds.l    1
  1092.  
  1093. sourcenamestart:
  1094.     ds.l    1
  1095.  
  1096. sourcenameend:
  1097.     ds.l    1
  1098.  
  1099. sourcenamelen:
  1100.     ds.l    1
  1101.  
  1102. commandstart:
  1103.     ds.l    1
  1104.  
  1105. commandend:
  1106.     ds.l    1
  1107.  
  1108. commandlen:
  1109.     ds.l    1
  1110.  
  1111. dosbase:
  1112.     ds.l    1
  1113.  
  1114. spacenumber:
  1115.     ds.l    1
  1116.  
  1117. col:
  1118.     ds.w    1
  1119.  
  1120. mode:
  1121.     ds.b    1
  1122.  
  1123. sourcename:
  1124.     ds.b    256
  1125.  
  1126. destname:
  1127.     ds.b    256
  1128.  
  1129. sourcebuf:
  1130.     ds.b    1024
  1131.  
  1132. destbuf:
  1133.     ds.b    2048
  1134.  
  1135. spacebuf:
  1136.     ds.b    1024
  1137.  
  1138. numberbuf:
  1139.     ds.b    10
  1140.  
  1141. tabsize:
  1142.     ds.b    1
  1143.  
  1144. spacesize:
  1145.     ds.b    1
  1146.  
  1147. mode_case:
  1148.     ds.b    1
  1149.  
  1150. len_helptext    =    text_credits-text_helptext
  1151. len_credits    =    text_cursoroff-text_credits
  1152.